package edu.hubu.work01.Service.impl;

import edu.hubu.work01.entity.Cowshed;
import edu.hubu.work01.mapper.CowshedMapper;
import edu.hubu.work01.Service.CowshedService;
import edu.hubu.work01.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CowshedServiceImpl implements CowshedService {

    @Autowired
    private CowshedMapper cowshedMapper;
    public ResultVO saveCowshed(Cowshed cowshed){

        int i = cowshedMapper.insertCowshed(cowshed);

        if (i > 0) {
            return new ResultVO(200, "添加成功！", null);
        } else {
            return new ResultVO(500, "添加失败！", null);
        }
    };
    public ResultVO removeCowshed(int cshdId){
        int i = cowshedMapper.deleteCowshed(cshdId);
        if (i > 0) {
            return new ResultVO(200, "删除成功！", null);
        } else {
            return new ResultVO(500, "删除失败！", null);
        }
    };
    public ResultVO selectById(int cshdId){
        Cowshed cowshed = cowshedMapper.selectById(cshdId);
        if (cowshed != null) {
            return new ResultVO(200, "查询到", cowshed);
        } else {
            return new ResultVO(500, "没有", cowshed);
        }
    }
    public ResultVO selectByUserId(int userId){
        List<Cowshed> cowshed = cowshedMapper.selectByUserId(userId);
        if (cowshed != null) {
            return new ResultVO(200, "查询到", cowshed);
        } else {
            return new ResultVO(500, "没有", cowshed);
        }
    };
}
